package GUI;


import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import client.ClientConsole;

import Library.LendingHistoryStudent;

/**
 * @author mishel hen
 *
 */
/**
 * This class is the lending history to student
 */
public class GUI_LendingHistoryStudent extends JPanel{
	/**
	 * client Connected
	 */
	private ClientConsole clc;
	/**
	 * table
	 */
	private JTable table;
	/**
	 * list for lending history student
	 */
	private ArrayList<LendingHistoryStudent> loansHistory;
	/**
	 * Displays a table with lending history 
	 * @param cc
	 * @param history 
	 * @param mms
	 */
	public GUI_LendingHistoryStudent(ClientConsole cc, ArrayList<LendingHistoryStudent> history, final GUI_MainMenuStudent mms) {
			
			setLayout(null);
			//this.userName=userName;
			this.setSize(600, 400);
			clc=cc;
			loansHistory=history;
			
			JLabel lblTitle = new JLabel("Loans:");
			lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 20));

			lblTitle.setBounds(95, 15, 186, 25);
			add(lblTitle);
			
	
			JButton btnBack = new JButton("Back");
			btnBack.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					clc.cgui.setContentPane(mms);
				}
			})
			;
			btnBack.setBounds(95, 370, 100, 30);
			add(btnBack);
			
			
			showResults();
			
		}
		/**
		 * Displays a table with lending history 
		 * @param cc
		 * @param history 
		 * @param src
		 */
		
		public GUI_LendingHistoryStudent(ClientConsole cc,ArrayList<LendingHistoryStudent> history, final Gui_ShowReaderCard src) {
			setLayout(null);
			//this.userName=userName;
			this.setSize(600, 400);
			clc=cc;
			loansHistory=history;
			
			JLabel lblTitle = new JLabel("Delays in returning:");
			lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 20));

			lblTitle.setBounds(95, 15, 186, 25);
			add(lblTitle);
			
	
			JButton btnBack = new JButton("Back");
			btnBack.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					clc.cgui.setContentPane(src);
				}
			})
			;
			btnBack.setBounds(95, 370, 100, 30);
			add(btnBack);
			
			
			showResults();
		// TODO Auto-generated constructor stub
	}


		public void showResults() {
			

			JScrollPane scrollPane = new JScrollPane();
			scrollPane.setBounds(95, 70, 500, 300);
			add(scrollPane);
			
		
			
			table = new JTable(loansHistory.size(),4);
			scrollPane.setViewportView(table);
			
			table.getColumnModel().getColumn(0).setHeaderValue("BookName");
			table.getColumnModel().getColumn(1).setHeaderValue("loan Date");
			table.getColumnModel().getColumn(2).setHeaderValue("return date");
			table.getColumnModel().getColumn(3).setHeaderValue("copy id");
							
			
			
			
			for(int i=0;i<loansHistory.size();i++)
			{
				
					table.setValueAt(loansHistory.get(i).getBookName(),i,0);
					table.setValueAt(loansHistory.get(i).getLoanDate(),i,1);
					table.setValueAt(loansHistory.get(i).getReturnDate(),i,2);
					table.setValueAt(loansHistory.get(i).getCopyId(),i,3);

			}
			
			
			
			
		
		}
	

		
	}

